package com.neuedu.hcp.controller;


import com.neuedu.hcp.entity.Patient;
import com.neuedu.hcp.entity.RecoveryPlan;
import com.neuedu.hcp.entity.RespBean;
import com.neuedu.hcp.entity.RespPageBean;
import com.neuedu.hcp.service.IPatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第八组
 * @since 2021-04-26
 */
@RestController
@RequestMapping("/patient")
public class PatientController {
    @Autowired
    IPatientService patientService;

    @GetMapping("/List")
    public List<Patient> findAllPatient(){
        List<Patient> list = patientService.list(null);
        return  list;
    }
    /**
     * 分页展示数据
     * @param currentPage
     * @param size
     * @param patient
     * @return
     */
    @GetMapping("/planList")
    public RespPageBean list(@RequestParam(defaultValue = "1") Integer currentPage,
                             @RequestParam(defaultValue = "10") Integer size,
                             Patient patient){
        return patientService.getPatientListByPage(currentPage,size,patient);
    }

    /**
     * 插入
     * @param patient
     * @return
     */
    @GetMapping("/insert")
    public RespBean insert(Patient patient) {
        if (patientService.insert(patient) <= 0) {
            return RespBean.error("插入失败");
        }
        return RespBean.success("插入成功");
    }

    @PostMapping("/update")
    public RespBean update(@RequestBody Patient patient){
        if(patientService.updateById(patient)){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    /**
     * 删除
     * @param patientId
     * @return
     */
    @GetMapping("/delete")
    public RespBean delete( @RequestParam Integer patientId){
        if(patientService.removeById(patientId)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

}
